﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LevenBlog.Core.Data;
using LevenBlog.Core.Entities;

namespace LevenBlog.Core.Service
{
    public static class Image
    {
        public static int Count(IDbProvider provider)
        {
            return ProviderManager.Factory.Image.Count(provider);
        }

        public static int Count(IDbProvider provider, int typeid)
        {
            return ProviderManager.Factory.Image.CountFromTypeID(provider, typeid);
        }

        public static lb_image Get(IDbProvider provider, int id)
        {
            lb_image image = ProviderManager.Factory.Image.Get(provider, id);
            image.ImageType = ImageType.Get(provider).Single(it => it.id == image.typeid);
            return image;
        }

        public static IList<lb_image> GetFromTypeID(IDbProvider provider, int typeid)
        {
            IList<lb_image> imageList = ProviderManager.Factory.Image.GetFromTypeID(provider, typeid);
            foreach (lb_image image in imageList)
            {
                image.ImageType = ImageType.Get(provider).Single(it => it.id == image.typeid);
            }
            return imageList;
        }

        public static void Update(IDbProvider provider, lb_image image)
        {
            ProviderManager.Factory.Image.Update(provider, image);
        }

        public static void Insert(IDbProvider provider, lb_image image)
        {
            ProviderManager.Factory.Image.Insert(provider, image);
        }

        public static void Delete(IDbProvider provider, int id)
        {
            ProviderManager.Factory.Image.Delete(provider, id);
        }

        public static void DeleteFromTypeID(IDbProvider provider, int typeid)
        {
            ProviderManager.Factory.Image.DeleteFromTypeID(provider, typeid);
        }
    }
}
